package com.example.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.blankj.utilcode.util.SPUtils;
import com.example.activity.AddCourseActivity;
import com.example.activity.MainActivity;
import com.example.activity.SettingActivity;
import com.example.content.Constant;
import com.example.xc.R;

/**
 * 我的
 */
public class UserFragment extends Fragment {

    /**
     * 本方法用于创建Fragment布局
     */
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.user_fragment, container, false);            //关联布局文件
        initView(view);
        return view;
    }

    /**
     * 本方法用于显示页面时刷新数据
     */
    @Override
    public void onResume() {
        super.onResume();

        MainActivity.initUserBtnColor();
    }

    /**
     * 用于初始化用于入口控件
     *
     * @param view 传入我的页面布局对象
     */
    @SuppressLint("Range")
    private void initView(View view) {
        TextView name = view.findViewById(R.id.login_name);
        String loginName = SPUtils.getInstance().getString(Constant.isLoginIn);
        name.setText(String.format("用户名：%s", loginName));
        // 选课
        TextView tvlass = view.findViewById(R.id.info);
        tvlass.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), AddCourseActivity.class);
                getActivity().startActivity(intent);
            }
        });

        // 历史订单
        TextView record = view.findViewById(R.id.order);
        record.setOnClickListener(view12 -> {
            Intent intent = new Intent(getActivity(), SettingActivity.class);
            getActivity().startActivity(intent);
        });
    }
}
